package com.wanpinghui.wphlibrary.model.product.bean;

import org.xutils.db.annotation.Column;
import org.xutils.db.annotation.Table;

import java.util.List;

/***
 * 功能描述:产品数据模型
 * 作者:qiujialiu
 * 时间:2017/12/20
 ***/
@Table(name = "cart_product_list")
public class ProductBean {
    /**
     * allParamList (Array[产品具体技术参数传输对象], optional): 技术参数列表(所有) ,
     * area_lower (integer, optional),
     * area_upper (integer, optional),
     * brand (string, optional): 品牌 ,
     * brand_id (integer, optional): 品牌id ,
     * cart_item_quantity (integer, optional): 购物车数量 ,
     * color (integer, optional),
     * created_at (integer, optional),
     * deleted_at (integer, optional),
     * delivery_period (integer, optional): 交货期 ,
     * distance_lower (integer, optional),
     * distance_upper (integer, optional),
     * id (integer, optional): 主键 ,
     * is_consult (boolean, optional): 是否议价 ,
     * main_img (string, optional): 产品主图 ,
     * max_price (number, optional): 最高价 ,
     * min_price (number, optional): 最小价 ,
     * min_quantity (integer, optional): 最小起订量 ,
     * name (string, optional): 产品名称 ,
     * otherParams (Array[产品具体技术参数传输对象], optional): 选填技术参数 ,
     * pictures (string, optional): 相册 ,
     * pixel_lower (integer, optional),
     * pixel_upper (integer, optional),
     * price (number, optional),
     * product_desc_id (integer, optional): 产品报价id ,
     * product_drafts_id (integer, optional): 产品草稿id ,
     * product_type_id (integer, optional): 产品分类id ,
     * quoted_price (boolean, optional): 是否报价 ,
     * remark (string, optional),
     * requiredParams (Array[产品具体技术参数传输对象], optional): 必填技术参数 ,
     * scene (integer, optional),
     * second_name (string, optional): 副标题 ,
     * source (string, optional),
     * specList (Array[批发商自行供货价格记录传输对象], optional): 规格信息列表(带报价) ,
     * spec_settings (string, optional): 规格项配置 ,
     * status (integer, optional): 状态:1上架/0下架 ,
     * suggest_price (number, optional): 参考价 ,
     * supplier_id (integer, optional): 批发商id ,
     * titleParams (Array[产品具体技术参数传输对象], optional): 标题参数 ,
     * transport (integer, optional),
     * updated_at (integer, optional),
     * warranty_period (integer, optional): 保修期 ,
     * waterproof (integer, optional),
     * weight (integer, optional)
     */
    public ProductBean() {}

    public ProductBean(int id) {
        this.id = id;
    }

    @Column(name = "id", isId = true, autoGen = false)
    private int id;

    @Column(name = "name")
    private String name;

    @Column(name = "price")
    private double price;

    @Column(name = "count")
    private int selectCount;//选择的数量，本地字段

    @Column(name = "main_img")
    private String main_img;

    private List<ProductParamsBean> allParamList;

    @Column(name = "area_lower")
    private int area_lower;

    @Column(name = "area_upper")
    private int area_upper;

    @Column(name = "brand")
    private String brand;

    @Column(name = "brand_id")
    private int brand_id;

    @Column(name = "color")
    private int color;

    @Column(name = "create_at")
    private long create_at;

    @Column(name = "deleted_at")
    private long deleted_at;

    @Column(name = "delivery_period")
    private long delivery_period;

    @Column(name = "distance_lower")
    private int distance_lower;

    @Column(name = "distance_upper")
    private int distance_upper;

    @Column(name = "max_price")
    private double max_price;

    @Column(name = "min_price")
    private double min_price;

    @Column(name = "min_quantity")
    private int min_quantity;

    private List<ProductParamsBean> otherParams;

    //@Column(name = "pictures")
    //private List<String> pictures;

    @Column(name = "pixel_lower")
    private int pixel_lower;

    @Column(name = "pixel_upper")
    private int pixel_upper;

    @Column(name = "product_desc_id")
    private int product_desc_id;

    @Column(name = "product_drafts_id")
    private int product_drafts_id;

    @Column(name = "product_type_id")
    private int product_type_id;

    @Column(name = "quoted_price")
    private boolean quoted_price;

    @Column(name = "remark")
    private String remark;

    private List<ProductParamsBean> requiredParams;

    @Column(name = "scene")
    private int scene;

    @Column(name = "second_name")
    private String second_name;

    @Column(name = "source")
    private String source;

    private List<ProductFormatBean> specList;

    @Column(name = "status")
    private int status;

    @Column(name = "suggest_price")
    private double suggest_price;

    private List<ProductParamsBean> titleParams;

    @Column(name = "transport")
    private int transport;

    @Column(name = "updated_at")
    private long updated_at;

    @Column(name = "warranty_period")
    private int warranty_period;

    @Column(name = "waterproof")
    private int waterproof;

    @Column(name = "weight")
    private int weight;

    @Column(name = "cart_count")
    private int cart_item_quantity;

    private boolean is_consult;

    private int supplier_id;

    public String getName() {
        return name;
    }

    public int getFormatCount() {
        if (specList == null) {
            return 0;
        }
        return specList.size();
    }

    public String getMainImage() {
        return main_img;
    }

    public double getPrice() {
        return price;
    }

    public List<ProductFormatBean> getFormatList() {
        return specList;
    }

    public int getId() {
        return id;
    }

    public int getSelectCount() {
        return selectCount;
    }

    public int getCart_item_quantity() {
        return cart_item_quantity;
    }

    public void setSelectCount(int selectCount) {
        this.selectCount = selectCount;
    }

    public void setFormatList(List<ProductFormatBean> formatList) {
        this.specList = formatList;
    }

    public void clearFormatCount() {
        setSelectCount(0);
        if (specList != null && specList.size() > 0) {
            for (ProductFormatBean bean : specList) {
                bean.setCount(0);
            }
        }
    }

    public boolean isIs_consult() {
        return is_consult;
    }

    public int getProduct_desc_id() {
        return product_desc_id;
    }

    public int getProduct_type_id() {
        return product_type_id;
    }


    public int getCount() {
        return selectCount;
    }

    public String getSecond_name() {
        return second_name;
    }

    public boolean isQuoted_price() {
        return quoted_price;
    }

    public double getMax_price() {
        return max_price;
    }

    public double getMin_price() {
        return min_price;
    }

    public int getSupplier_id() {
        return supplier_id;
    }

    public void setCart_item_quantity(int cart_item_quantity) {
        this.cart_item_quantity = cart_item_quantity;
    }

    /**
     * 获取所有规格在购物车的总数
     * @return
     */
    public int getAllSelectCount() {
        if (getFormatList() != null && getFormatList().size() > 0) {
            int quantity = 0;
            for (ProductFormatBean formatBean : getFormatList()) {
                quantity += formatBean.getCount();
            }
            return quantity;
        }else {
            return getCount();
        }
    }

    public void resetSelectCount() {
        if (getFormatList() != null && getFormatList().size() > 0) {
            for (ProductFormatBean formatBean : getFormatList()) {
                formatBean.setCount(formatBean.getCart_item_quantity());
            }
        }else {
            selectCount = cart_item_quantity;
        }
    }

    public void resetSelectCountToZero() {
        if (getFormatList() != null && getFormatList().size() > 0) {
            for (ProductFormatBean formatBean : getFormatList()) {
                formatBean.setCount(0);
            }
        }else {
            selectCount = 0;
        }
    }
}
